// --------------------
// -- COMMAND & QUE
#include "que.h"
#include "command.h"

#define T3_5 1750

que Q;
command C, cOut;


void processSerial(){
    int temp;
    temp = getCommand();
    while (temp) {
        processQue();
        processCommand();
        temp = getCommand();
    }
}

int getCommand(){
    while (Serial.available() > 0) {
        uint8_t temp = Serial.read();
        enque(&Q,temp);
                
        if (temp == DELIMITERREP) {
            return 1;
        }
    }
    return 0;
}

void processQue(){
    C = parseQue (Q);
}

void processCommand(){
    
    switch (C.commandType){
        
        case REPID_CMD:       

            getAbs = C.value[0];
            getOrd = C.value[1];
            //idProg_updateAbsisOrdinatInt(getAbs , getOrd);
            #ifdef DEBUG_SER
            Serial.println("REPID_CMD");
            Serial.print("GOT ( ");
            Serial.print(getAbs);
            Serial.print(" , ");
            Serial.print(getOrd);
            Serial.println(")");
            #endif
       
        break;
    }

}

void sendCOut(){
    if (cOut.commandType != BROKEN_CMD){
        que qOut = makeQue(cOut);
        
        set485Mode(TX485);       
        
        for (int i=0; i<6; ++i){
            char temp2 = deque(&qOut);
            Serial.write(temp2);
        }
        
        Serial.flush();          
        set485Mode(RX485);
        
        delayMicroseconds(T3_5);
    }
}


